﻿Imports System.Threading

Public Class Main
    Dim dot As String = ""
    Dim t As Thread
    Dim da As New DSVaultingTableAdapters.user_acountTableAdapter

    Private Sub btn_edit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_edit.Click
        frmLogin.Show()
    End Sub

    Private Sub connectingProcess()
        Do While True
            If CheckDBServer("localhost", "3306") Then
                uxStatuslb.Text = "Connected"
                Me.Invoke(New MethodInvoker(AddressOf enableControl))
            Else
                Me.Invoke(New MethodInvoker(AddressOf disableControl))
                If dot = "...." Then
                    dot = ""
                End If
                dot += "."
                uxStatuslb.Text = "Connecting" & dot
            End If
            Thread.Sleep(1000)
        Loop
    End Sub

    Private Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        disableControl()
        t = New Thread(AddressOf connectingProcess)
        t.Start()
    End Sub

    Private Sub Main_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
        t.Abort()
    End Sub

    Private Sub btn_view_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_view.Click
        frmMonthYearPicker.Show()
        frmLogin.UserRole = "guest"
    End Sub

    Private Sub enableControl()
        btn_edit.Enabled = True
        btn_view.Enabled = True
    End Sub

    Private Sub disableControl()
        btn_edit.Enabled = False
        btn_view.Enabled = False
    End Sub

    Public Sub Destroy()
        Finalize()
        System.GC.SuppressFinalize(Me)
    End Sub
End Class
